//
//  ChangeEmailController.m
//  DYLYJ
//
//  Created by JM on 15/11/23.
//  Copyright © 2015年 JM. All rights reserved.
//

#import "ChangeEmailController.h"
#import "DYRequestAll.h"
#import "AppDelegate.h"
#import "NSString-Helper.h"
#import "DYUIKit.h"
@interface ChangeEmailController ()
@property(nonatomic,strong)IBOutlet UITextField *emailTextField ;
@end

@implementation ChangeEmailController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (IBAction)clickChangeEmail:(id)sender {
    [self.view endEditing:YES];
    if (self.emailTextField.text.length == 0){
        [MJAlertView showMessage:@"请输入邮箱"];
        return;
    }
    if (![NSString isValidateEmail:self.emailTextField.text]){
         [MJAlertView showMessage:@"邮箱格式错误"];
        return;
    }
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    BlindEmailRequest *request = [BlindEmailRequest request];
    request.DY_token = myAppDelegate.token;
    request.DY_email = self.emailTextField.text;
    [request requstWithCompletionHandler:^(DYResponse *rs, NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [MBProgressHUD hideHUDForView:self.view animated:YES];
        });
        if (error) {
            [MJAlertView showMessage:error.localizedDescription];
            return ;
        }
        [MJAlertView showAlertViewWithTitle:@"提示" message:@"修改邮箱成功" clickedButtonBlock:^(NSInteger index) {
            [self.navigationController popToRootViewControllerAnimated:YES];
        } cancelButtonTitle:@"确定" otherButtonTitles:nil];
//        myAppDelegate.uid = nil;
//        myAppDelegate.token = nil;
//        myAppDelegate.islogin = NO;
//        [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    }];
}



@end
